<?php
foreach($partnerlang as $langkey=>$langval){
    $title[$langkey] = (set_value('title'.$langkey) == '')?$offerdetails['title'.$langkey]:set_value('title'.$langkey);
    $desc[$langkey] = (set_value('desc'.$langkey) == '')?$offerdetails['desc'.$langkey]:set_value('desc'.$langkey);
}
$hotel_id = (set_value('hotel_id') == '')?$offerdetails['hotel_id']:set_value('hotel_id');
$offer_start = (set_value('offer_start') == '')?$offerdetails['offer_start']:set_value('offer_start');
$offer_end = (set_value('offer_end') == '')?$offerdetails['offer_end']:set_value('offer_end');
$status = (set_value('status') == '')?$offerdetails['status']:set_value('status');

$id = ($this->input->post('id') == '')?$offerdetails['offer_id']:$this->input->post('id');
$action=(($offerdetails['id'] || $this->input->post('id')!='')?"doaddoffer":"doaddoffer");
?>

<?php
//$set_txtContactName = (set_value('txtContactName') == '')?$hoteldetails['txtContactName']:set_value('txtContactName');
?>
<div class="form_content">
    <header><h3>Add New Offer</h3></header>
    <div class="module_content">
        <?php //echo validation_errors(); ?>
        <form name="offerform" id="offerform"  action="<?php echo base_url(); ?>secu/offer/<?php echo $action;?>" method="post" onsubmit="return validateForm()" >
        <input type="hidden" name="id" id="id" value="<?php echo $id; ?>">
        <fieldset style="width:40%;">
            <label style="width: 10%;">Hotel</label>
            <select name="hotel_id" id="hotel_id" style="width: 220px;">
                <option value="">Select star level</option>
                <?php foreach ($hotel_arr as $val) :?>                    
                    <option value="<?php echo $val['hotel_id']; ?>" <?php echo ($hotel_id==$val['hotel_id']?"selected=selected":"")?>><?php echo $val['hotelname']; ?></option>
                <?php endforeach; ?>
            </select>
             <?php echo form_error('hotel_id'); ?>
        </fieldset>
        <?php foreach($partnerlang as $langkey=>$langval):?>
        <fieldset>          
            <label> Offer Title (<?php echo $langval;?>)</label>
            <input type="text" name="title<?php echo $langkey?>" id="title<?php echo $langkey?>" value="<?php echo $title[$langkey] ?>" />        
        </fieldset>
        <?php endforeach;?>
        <?php foreach($partnerlang as $langkey=>$langval):?>
        <fieldset>
            <label>Description (<?php echo $langval;?>):</label>
            <!--<textarea rows="4" name="txtHdescriptions<?php //echo $langkey?>" id="txtHdescriptions<?php //echo $langkey?>" /></textarea>-->
            <div style="padding: 0 0 0 10px;">
            <?php $this->editorfck->load('desc' . $langkey, $desc[$langkey], '95%', 300); ?>
            </div>
        </fieldset>
        <?php endforeach;?>    
        <fieldset>          
            <label>Offer Start </label>
            <input type="text" name="offer_start" id="offer_start" value="<?php echo $offer_start ?>" />        
        </fieldset>
        <fieldset>          
            <label>Offer End </label>
            <input type="text" name="offer_end" id="offer_end" value="<?php echo $offer_end ?>" />        
        </fieldset>
        <fieldset style="width:40%;">
            <label style="width: 10%;">Status</label>
            <input <?php echo ($status==1)?"checked":""; ?> type="checkbox" name="status" value="1" style="width:20%;">
             <?php echo form_error('status'); ?>
        </fieldset>
        <fieldset>
            <input type="submit" name="submit" id="submit" value="SAVE"  >&nbsp;
            <input type="reset" name="reset" id="reset" value="RESET" >
        </fieldset>
        
        <div class="clear"></div>
        </form>
    </div>



</div>
<script>
$(function() {
        $( "#offer_start" ).datepicker({dateFormat: "yy-mm-dd"});
        $( "#offer_end" ).datepicker({dateFormat: "yy-mm-dd"});
});
</script>
<script type="text/javascript">

 function validateForm()
 {
     <?php foreach($partnerlang as $langkey=>$langval){?>
     var hotelname<?php echo $langval?>=document.forms["offerform"]["title<?php echo $langval?>"].value;
     var hotelname<?php echo $langval?>=document.forms["offerform"]["desc<?php echo $langval?>"].value;
     <?php } ?>
     var numBeds=document.forms["offerform"]["numBeds"].value;
     var numStars=document.forms["offerform"]["numStars"].value;
     var accchecked=document.getElementsByName('accomodation[]');
     var txtPhoneNo=document.forms["offerform"]["txtPhoneNo"].value;
     var txtFaxNo=document.forms["offerform"]["txtFaxNo"].value;
     var txtWebAddress=document.forms["offerform"]["txtWebAddress"].value;
     var txtEmailAddress=document.forms["offerform"]["txtEmailAddress"].value;
     var txtContactName=document.forms["offerform"]["txtContactName"].value;

     if (!hascheckboxes(accchecked))
      {
          alert("Please Select a Accommodation Type");
          accchecked[0].focus();
          return false;
      }
      <?php foreach($partnerlang as $langkey=>$langval){?>
    if (title+<?php echo $langval?>==null || title+<?php echo $langval?>=="")
      {
          alert("Please Enter the Title-<?php echo $langval?>");
          document.getElementById("title<?php echo $langval?>").focus();
          return false;
      }
    if(desc+<?php echo $langval?>==null || desc+<?php echo $langval?>=="")
         {
          alert("Please Enter the Description-<?php echo $langval?>");
          document.getElementById("desc<?php echo $langval?>").focus();
          return false;
      }
      <?php } ?>
     if(numBeds==null || numBeds=="" || !isNumber(numBeds))
         {
          alert(" Please enter a valid hotel room #");
          document.getElementById("numBeds").focus();
          return false;
      }
       if(numStars==null || numStars=="" || !isNumber(numStars))
         {
          alert(" Please select a star status");
          document.getElementById("numStars").focus();
          return false;
      }
       if(numBeds==null || numBeds=="" || !isEmail(txtEmailAddress))
      {
               alert("Please enter a valid Email");
          document.getElementById("txtEmailAddress").focus();
          return false;
      }
      if(txtContactName==null || txtContactName=="")
      {
          alert(" Please enter a valid Contact name");
          document.getElementById("txtContactName").focus();
          return false;
      }

      if((txtPhoneNo!=""))
      {
             if(!isNumber(txtPhoneNo) || txtPhoneNo.length>11){
                  alert("Please enter a valid phone no");
                  document.getElementById("txtPhoneNo").focus();
                  return false;
             }

      }
      if ((txtFaxNo!=""))
       {
          if(!isNumber(txtFaxNo) || txtFaxNo.length>11){
              alert("Please enter a valid fax no");
              document.getElementById("txtFaxNo").focus();
              return false;
          }
        }

       if((txtWebAddress!="" ))
      {
          if(!isURL(txtWebAddress))
              {
                      alert("Please enter a valid Web Address");
                      document.getElementById("txtWebAddress").focus();
                      return false;
              }

      }


 }
</script>



